<template>
    <div>
        <h2>会员信息列表</h2>
        <input type="button" value="新增" class="btn-btn-primary" @click="add">
        会员名称：
        <input type="text" v-model="cha.name">
        会员级别：
        <select v-model="cha.lid">
            <option value="">请选择</option>
            <option :value="item.Id" v-for="item in quertinfo.data" :key="item.Id">{{ item.Name }}</option>
        </select>
        <input type="button" value="查询" class="btn btn-primary" @click="showinfo">
        
        <table class="table table-bordered">
            <tbody>
                <tr class="bg-primary">
                    <td>会员名称</td>
                    <td>性别</td>
                    <td>手机号码</td>
                    <td>会员级别</td>
                    <td>积分</td>
                    <td>累计额消费金额</td>
                    <td>注册时间</td>
                    <td>操作</td>
                </tr>

                <tr v-for="item in quertinfo1.data" :key="item.Id">
                    <td>{{ item.Name }}</td>
                    <td>{{ item.Sex == 0 ? "男" : "女" }}</td>
                    <td v-if="item.Phone">{{ item.Phone.substring(0, 3) + '****' + item.Phone.substring(7) }}</td>
                    <td>
                        <span v-if="item.Lid == 1">黄金会员</span>
                        <span v-if="item.Lid == 2">钻石会员</span>
                        <span v-if="item.Lid == 3">至尊会员</span>
                    </td>
                    <td>{{ item.JiFen }}</td>
                    <td v-if="item.Money">￥{{ item.Money.toFixed(2) }}</td>
                    <td>{{ moment(item.CreateTime).format('YYYY-MM-DD HH:mm:ss') }}</td>
                    <td>
                        <input type="button" value="删除" class="btn btn-success" @click="del(item.Id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();
import moment from 'moment';

const add=()=>{
    router.push('/infoadd')
}

//删除
const del = (id: any) => {
    let f = confirm('确认删除吗')
    if (f) {
        axios({
            method: 'delete',
            url: '/api/Week/DelInfo',
            params:{
                id:id,
            }
        })
            .then(res => {
                console.log(res);
                if (res.data > 0) {
                    alert('成功');
                    showinfo();
                }
                else {
                    alert('失败')
                }
            })
    }

}

//下拉框
//生命周期函数
onMounted(() => {
    showlevel();
    showinfo();
})

let quertinfo: any = reactive({
    data: []
})

const showlevel = () => {
    axios({
        method: 'get',
        url: '/api/Week/Showlevel'
    })
        .then(res => {
            console.log(res);
            quertinfo.data = res.data
        })
        .catch(err => {
            console.error(err);
        })
}

let cha = reactive({
    name: '',
    lid: ''
})

let quertinfo1: any = reactive({
    data: []
})
const showinfo = () => {
    axios({
        method: 'get',
        url: '/api/Week/Showinfo',
        params: cha
    })
        .then(res => {
            console.log(res);
            quertinfo1.data = res.data;
        })
        .catch(err => {
            console.error(err);
        })

}
</script>

<style scoped></style>